package com.zjt;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;


/**
 * 节点类，维护后继节点的引用
 */
public class Node {

    /**
     * 所有指向后继节点的边
     * 只能添加，不允许删除
     *
     * @see Edge
     */
    private final List<Edge> successors = new LinkedList<>();

    /**
     * 节点的ID
     */
    private final int id;

    public Node(int id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node node = (Node) o;
        return id == node.id;
    }

    public void addSuccessor(Edge e) {
        successors.add(e);
    }

    public List<Edge> getSuccessors() {
        return successors;
    }

    public int getId() {
        return id;
    }

    @Override
    public String toString() {
        return "Node{" +
                "id=" + id +
                '}';
    }

    @Override
    public int hashCode() {
        return this.id;
    }

    public static void main(String[] args) {
        Node n1 = new Node(12);
        Node n2 = new Node(11);
        Node n3 = new Node(12);

        Set<Node> nodes = new HashSet<>();
        nodes.add(n1);
        nodes.add(n2);
        nodes.add(n3);
        
        System.out.println(nodes.size());
        System.out.println(n1.equals(n3));
    }
}
